<!-- 承运商车辆列表 -->
<template>
  <el-dialog
    title="分配组别"
    :visible.sync="dialogVisible"
    append-to-body
    width="30%"
  >
    <avue-select
      style="width: 100%"
      multiple
      v-model="carrierGroup"
      placeholder="请选择内容"
      :props="{ label: 'name', value: 'name' }"
      :dic="dic"
    ></avue-select>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">关 闭</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { carrierGroup, assignGroup } from "@/api/basedata/carriers";

export default {
  data() {
    return {
      dialogVisible: false,
      carrierGroup: [],
      dic: [],
      carrierId: "",
    };
  },
  components: {},
  computed: {},
  methods: {
    open(id, carrierGroup) {
      this.dialogVisible = true;
      this.carrierGroup = carrierGroup ? carrierGroup.split(",") : [];
      this.carrierId = id;
      this.getList();
    },
    getList() {
      this.loading = true;
      carrierGroup().then((res) => {
        this.loading = false;
        this.dic = res;
      });
    },
    submit() {
      assignGroup({
        id: this.carrierId,
        group: this.carrierGroup.join(","),
      }).then(
        () => {
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          this.$emit("refresh");
          this.dialogVisible = false;
        },
        (error) => {
          window.console.log(error);
        }
      );
    },
  },
};
</script>

<style></style>
